package com.example.Utils;

import com.example.Entity.Vo.APIResult;

import java.util.Date;

public class APIResultUtils {
    /**
     * 成功的方法组
     * @param message 信息
     * @param data 数据
     * @return APIResult定义的返回类型
     */
    public static APIResult success(String message,Object data){
        APIResult apiResult = new APIResult();
        apiResult.setIssuccess(true);
        apiResult.setErrcode(0);
        apiResult.setData(data);
        apiResult.setMessage(message);
        apiResult.setCode(0);
        apiResult.setTimestamp(new Date());
        return apiResult;
    }
    public static APIResult success(String message){
        APIResult apiResult = new APIResult();
        apiResult.setIssuccess(true);
        apiResult.setErrcode(0);
        apiResult.setData("");
        apiResult.setMessage(message);
        apiResult.setCode(0);
        apiResult.setTimestamp(new Date());
        return apiResult;
    }
    public static APIResult success(){
        APIResult apiResult = new APIResult();
        apiResult.setIssuccess(true);
        apiResult.setErrcode(0);
        apiResult.setData("");
        apiResult.setMessage("");
        apiResult.setCode(0);
        apiResult.setTimestamp(new Date());
        return apiResult;
    }

    /**
     * 失败的方法组
     * @param message 信息
     * @param data 数据
     * @param errcode 错误码
     * @return APIResult定义的返回类型
     */
    public static APIResult error(String message,Object data,int errcode){
        APIResult apiResult = new APIResult();
        apiResult.setIssuccess(false);
        apiResult.setErrcode(errcode);
        apiResult.setData(data);
        apiResult.setMessage(message);
        apiResult.setCode(1);
        apiResult.setTimestamp(new Date());
        return apiResult;
    }

    public static APIResult error(String message,int errcode){
        APIResult apiResult = new APIResult();
        apiResult.setIssuccess(false);
        apiResult.setErrcode(errcode);
        apiResult.setData("");
        apiResult.setMessage(message);
        apiResult.setCode(1);
        apiResult.setTimestamp(new Date());
        return apiResult;
    }

    public static APIResult error(String message,Object data){
        APIResult apiResult = new APIResult();
        apiResult.setIssuccess(false);
        apiResult.setErrcode(0);
        apiResult.setData(data);
        apiResult.setMessage(message);
        apiResult.setCode(1);
        apiResult.setTimestamp(new Date());
        return apiResult;
    }

    public static APIResult error(String message){
        APIResult apiResult = new APIResult();
        apiResult.setIssuccess(false);
        apiResult.setErrcode(0);
        apiResult.setData("");
        apiResult.setMessage(message);
        apiResult.setCode(1);
        apiResult.setTimestamp(new Date());
        return apiResult;
    }
}
